package parser

import (
	"log"
	"regexp"
	"wjerp.com/hello/crawler/engine"
)

const cityListRe = `<a href="(http://www.zhenai.com/zhenghun/[a-zA-Z0-9]+)"[^>]*>([^<]+)</a>`

func ParseCityList(contents []byte) engine.ParseResult {
	regex := regexp.MustCompile(cityListRe)
	matchResult := regex.FindAllSubmatch(contents, -1)
	log.Println("find city counts:",len(matchResult))
	parseResult := engine.ParseResult{}
	for _,result:= range matchResult{
		parseResult.Items = append(parseResult.Items,string(result[2]))
		parseResult.Requests = append(parseResult.Requests,engine.Request{
			Url: string(result[1]),
			ParseFunc: ParseCity,
		})
		log.Printf("城市：%s URL：%s\n",result[2],result[1])
	}
	return parseResult
}
